package util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.LongSerializationPolicy;

import java.lang.reflect.Type;

/**
 * @Author Antony
 * @Since 2017/11/21 11:46
 */
public class GsonUtil {


    private static GsonBuilder GSON_BUILDER = new GsonBuilder().disableHtmlEscaping()
            .setLongSerializationPolicy(LongSerializationPolicy.STRING)
            .setDateFormat("yyyy-MM-dd HH:mm:ss");
    private static Gson gson = GSON_BUILDER.create();

    public static String toJson(Object o){
        return gson.toJson(o);
    }

    public static <T> T fromJson(String json, Class<T> clazz){
        return gson.fromJson(json, clazz);
    }

    public static <T> T fromJson(String json, Type typeOf){
        return gson.fromJson(json, typeOf);
    }
}
